package com.example.rwq_test.jdkProxy;

import java.lang.reflect.Proxy;

/**
 * TODO note
 *
 * @author renweiqiang
 * @version 1.0.0
 * @createTime 2023/9/13
 */
public class Main {
    public static void main(String[] args) {
        // 创建目标对象
        MyInterface target = new MyInterface() {
            public void doSomething() {
                System.out.println("Real object doing something");
            }
        };

        // 创建InvocationHandler对象
        MyInvocationHandler handler = new MyInvocationHandler(target);

        // 创建代理对象
        MyInterface proxy = (MyInterface) Proxy.newProxyInstance(
                target.getClass().getClassLoader(),
                target.getClass().getInterfaces(),
                handler);

        // 调用代理对象的方法
        proxy.doSomething();
    }
}
